﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body class="no-skin">
<div class="main-content1">
<div class="breadcrumbs" id="breadcrumbs">
	<script type="text/javascript">
		try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
	</script>
	<ul class="breadcrumb"  style="margin-top:10px">
		<li>
			<i class="ace-icon fa fa-home home-icon"></i>
			<a href="#">后台管理</a>						</li>
		<li class="active">角色管理</li>
	</ul><!-- 路径结束 -->
</div>

<!-- /section:basics/content.breadcrumbs -->
<div class="page-content">
<div class="row">
<div class="tab-content no-border padding-0">
<div class="col-xs-12" >
	<!-- PAGE CONTENT BEGINS -->
		<div class="widget-box transparent">
			<div class="widget-header widget-header-small">
				<h4 class="widget-title blue smaller">
					<i class="ace-icon glyphicon glyphicon-file orange"></i>
						角色授权
				</h4>
			</div>
			<div class="widget-body">
				<div class="widget-main padding-8">
					<!-- #section:pages/profile.feed -->
						<div id="profile-feed-1" class="profile-feed">
							<form id="roleEditForm" class="form-horizontal" role="form">
								<div class="space-1">
								<input name="roleId" type="hidden" id="roleId" class="col-xs-6" value="${role.roleId}" />
								</div>
                                	<div class="form-group">
                                    	<label class="col-sm-3 control-label no-padding-right" for="form-field-1">角色代码</label>
                                    	<div class="col-sm-9">
                                    		<input name="roleCodeStr" type="text" id="roleCodeStr" disabled="disabled" class="col-xs-6" value="${role.roleCode}" />
                                    		<input name="roleCode" type="hidden" id="roleCode" class="col-xs-6" value="${role.roleCode}" />
										</div>
                                  	</div>
                                  	
								<div class="space-1"></div>
                                	<div class="form-group">
                                    	<label class="col-sm-3 control-label no-padding-right" for="form-field-1">角色名称</label>
                                    	<div class="col-sm-9">
                                    		<input name="roleName" type="text" id="roleName" class="col-xs-6" value="${role.roleName}" />
										</div>
                                  	</div>
                                  	
								<div class="space-1"></div>
                                	<div class="form-group">
                                    	<label class="col-sm-3 control-label no-padding-right" for="form-field-1">描述</label>
                                    	<div class="col-sm-9">
                                    		<textarea name="remark" rows="5" class="col-xs-6" id="remark">${role.remark}</textarea>
										</div>
                                  	</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
					
					<div class="col-sm-12">
					<div class="widget-box ">
			    		<div class="widget-header">
			    			<h4 class="widget-title lighter smaller">系统菜单</h4>
			    		</div>

			    		<div class="widget-body" style="height:auto; overflow-y:auto">
			    			<div class="widget-main padding-8">
			    				<ul id="treeDemo" class="ztree"></ul>
							</div>
							
							
						</div>
					</div>
				</div>
					
					
					
					<div class="col-xs-12" style="text-align:center"><!-- 按钮行-->

						<div class="clearfix form-actions" style="">
							
							<button class="btn btn-info" type="button"  onclick="submitRoleEditForm();">
								<i class="ace-icon fa fa-save bigger-110"></i>
									保 存	
							</button>
							<button class="btn" type="button"  onclick="toBack();">
								<i class="ace-icon fa fa-undo bigger-110"></i>
									返 回	
							</button>
						</div>
					</div>
					
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.page-content -->
</div><!-- /.main-content -->
	<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
		<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>			
	</a>		
</div><!-- /.main-container -->
	
	<link rel="stylesheet" href="${resRoot}/plugin/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script src="${resRoot}/plugin/zTree_v3/js/jquery.ztree.excheck-3.5.js"></script>
	<script src="${resRoot}/plugin/ace-v1.3/assets/js/jquery.validate.min.js"></script>
	<script src="${resRoot}/plugin/jquery-validation/localization/messages_zh.js"></script>
	<script type="text/javascript">
	
	//返回
	function toBack(){
		window.location.href="../../auth/role/toRoleManage.htm";
	}
		
	var setting={
	    	check: {
	    		enable: true,
				chkStyle: "checkbox",
				chkboxType: { "Y": "ps", "N": "s" }
				},
            data:{
	            simpleData:{
	            enable: true,
	            idKey:"resourceCode",
	            pIdKey:"parentCode",
	            rootPId:null
	            },
	            key:{
	                checked:"isChecked",
	                name:"resourceName"
	            }
            }
            
}; 
	
	//得到树
$(document).ready(function(){
    var roleCode = $("#roleCode").val();
    $.ajax({
        type:"POST",
        contentType: 'application/json',
        dataType:"json",
        url:contextPath+"/auth/role/getResourceTreeData.json?roleCode="+roleCode,
        success:function(data){
	        $.fn.zTree.init($("#treeDemo"), setting, data);
        },
        error:function(){
            $.Alert("系统错误！");
        }
    });
   });
	
	
		//获取选择的资源
		function getCheckRes() {
		    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		    var nodes = treeObj.getCheckedNodes(true);
		    var codeArr = new Array();
		    for(var i=0; i<nodes.length; i++){
		        codeArr.push(nodes[i].resourceCode+";"+nodes[i].resourceType);
		    }
		    return codeArr.join(",");
		}
		     
		     //提交表单函数
		     function submitRoleEditForm(){
		         var param = getCheckRes();
		       	if(validateForm()){
		         $.ajax({
		           url : contextPath + "/auth/role/editRole.json?resources="+param,
		           type : "post",
		           data : $("#roleEditForm").serialize(),
		           async : false,
		           success : function(data){
		             var msg = eval("("+data+")");
		             $.Alert(msg.message,'',toRoleManage);
		           },
		           error : function(){
		             //$.Alert("服务异常，请稍后尝试！");
		           }
		         });
		       }
		     }
		     
		     function toRoleManage(){
		     	location.href = "../../auth/role/toRoleManage.htm";
		     }
		     
		     //客户简称验证
		    //jQuery.validator.addMethod("dealerShtNameCheck",function(value,element){
		     //  var reg = /^[0-9a-zA-Z]+$/;
		      // return this.optional(element) || reg.test(value);
		    //},"客户简称只能为字母或数字");
		     
		     //表单验证函数
		     function validateForm(){
		       return $("#roleEditForm").validate({
		         errorElement : 'span',
				 errorClass : 'help-block',
				 focusInvalid : false,
				 rules : {
				   "roleName" : {
				    required : true
				   },
				   "remark":{
				   maxlength:500
				   }
				 },
				 
				 highlight: function (e) {
						$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
					},
			
					success: function (e) {
						$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
						$(e).remove();
					},
				 
				 
				 errorPlacement: function (error, element) {
						if(element.is(':checkbox') || element.is(':radio')) {
							var controls = element.closest('div[class*="col-"]');
							if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
							else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
						}
						else if(element.is('.select2')) {
							error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
						}
						else if(element.is('.chosen-select')) {
							error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
						}
						else if(element.is('textarea')) {
							error.appendTo(element.parent());
						}
						else if(element.is('input[type=text]')) {
							error.appendTo(element.parent());
						}
						else error.insertAfter(element.parent());
					}
		       }).form();
		     }
		     
		</script>
	</body>
</html>
